Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
Last Page that User Visited is Not Saving in "document.referrer"

I am trying a user to redirect back to the blog he was reading after signup & tried multiple methods but user is getting redirected to either 2nd last blog or the same page (signup). Details below.

LINK TO SITE I NEED HELP WITH

  • http://mintymind.flywheelsites.com/

GOAL

  • A user reads 1 blog, clicks on 2nd blog & gets redirected to signup page.
  • User gives his email & signs up.
  • Signup page gets refreshed & shows back button (to go to last blog user was reading)

WHATS HAPPENING

  • For some reason, the "Last blog" from where user gets redirected to is not getting stored in javascript: history.go(-1) or window.history.back()

  • When I use -1 in history functions mentioned above, it stays on the same sign page probably because it was refreshed but when I even user -2 in those above history functions, it goes to "2nd last blog" user read.

OTHER SOLUTION I TRIED

if (!sessionStorage.alreadyClicked) {
    var referrer = document.referrer;
    console.log(referrer);
      
      
    localStorage.setItem("protectedReferrer", referrer);
    var protectedReferrerForInsertion = localStorage.getItem("protectedReferrer");
      
    console.log("Saved Variable was" + protectedReferrerForInsertion);   
}

document.querySelector("#back-button-referrer a").setAttribute("href", protectedReferrerForInsertion);

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Redirecting URLs don't get added to history or the referrer. You can't rely on those to record where to send somebody back to when that URL originally redirected.

They way to solve this issue is to use a URL parameter of the page to return to when redirecting to the signup page. In other words: /second-blog-article should redirect to /signup?back=/second-blog-article. That back parameter needs to be passed the entire way through the sign up process and then you redirect to it once sign up is complete.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Hey using session solved my problem. Here is the code.

jQuery(document).ready(function( $ ){
    if (top.location.pathname === '/signup/'){

        var sessionCheck = sessionStorage.getItem('visited');
        
        if(sessionCheck == null || 0 ){
            sessionStorage.setItem("visited", 0);
        }
    
        var visited = sessionStorage.getItem('visited');
        
          if (visited == 0) {
            var referrer = document.referrer;
        
            sessionStorage.setItem("localReferrer", referrer);
            sessionStorage.getItem('localReferrer');
    
            $("#back-button-referrer a").attr("href", sessionStorage.getItem('localReferrer'));
            sessionStorage.setItem("visited", 1);
        }
        else{
            $("#back-button-referrer a").attr("href", sessionStorage.getItem('localReferrer'));
        }
    }

});

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda